package cn.doitedu.day07

import cn.doitedu.day06.Boy

//视图界定，就是为了实现隐式转换的，必须找到一个隐式转换方法或函数
class Pair3[T <% Ordered[T]] {

  //传入两个类型一样的参数，返回大的
  def bigger(first: T, second: T): T = {
    if (first >= second) first else second
  }

}

class Boy3(val name: String, val fv: Double) {

  override def toString = s"Boy3($name, $fv)"
}

object Pair3 {

  implicit def boyToOrderedBoy(boy3: Boy3): Ordered[Boy3] = {
    new Ordered[Boy3] {
      override def compare(that: Boy3): Int = {
        java.lang.Double.compare(that.fv, boy3.fv)
      }
    }
  }

  def main(args: Array[String]): Unit = {

    val b1 = new Boy3("tom", 99.99)
    val b2 = new Boy3("jerry", 88.88)
    //Pair3[T <% Ordered[T]]视图界定就是为了实现隐式转换，必须要有隐式转换方法或函数
    val p = new Pair3[Boy3]
    val res = p.bigger(b1, b2)

    println(res)


  }


}






